package edu.ssdut.revise.models;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.ConstructorDeclaration;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class VisConstructorNode extends VisBaseNode {
    private final List<String> annotations;
    private final String identifier;
    private final List<String> modifiers;
    private final String body;
    private final List<VisParamNode> parameters;

    /**
     * construct with ConstructorDeclaration
     *
     * @param cd constructorDeclaration
     */
    public VisConstructorNode(ConstructorDeclaration cd) {
        super(cd);
        // TODO: constructors can also have inner classes, consider extracting an interface to provide the ability to have inner classes;
        List<String> modifiers = cd.getModifiers().stream().map(Node::toString).collect(Collectors.toList());

        this.identifier = cd.getNameAsString();
        this.modifiers = modifiers;
        this.body = cd.getBody().toString();
        this.annotations = cd.getAnnotations().stream().map(Objects::toString).collect(Collectors.toList());
        this.parameters = cd.getParameters().stream().map(VisParamNode::new).collect(Collectors.toList());
    }

    @Override
    public String toString() {
        return "Method identifier: " + this.identifier + System.lineSeparator() +
                "  " + "method modifiers: " + this.modifiers.toString() + System.lineSeparator() +
                "  " + "annotations: " + annotations.toString() + System.lineSeparator() +
                "  " + "params: " + parameters.toString() + System.lineSeparator() +
                "  " + "method body: " + System.lineSeparator() +
                this.body + System.lineSeparator();
    }

    @Override
    public String getTypeName() {
        return "MethodNode";
    }

    public List<String> getAnnotations() {
        return annotations;
    }

    public String getIdentifier() {
        return identifier;
    }

    public List<String> getModifiers() {
        return modifiers;
    }

    public String getBody() {
        return body;
    }

    public List<VisParamNode> getParameters() {
        return parameters;
    }
}
